/*
 * SocketClient.h
 *
 *  Created on: Feb 14, 2012
 *      Author: hduser
 */

#ifndef SOCKETCLIENT_H_
#define SOCKETCLIENT_H_

#include <sys/types.h>
#include <sys/socket.h>

#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>

#include <netdb.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>

#include <unistd.h>
#include <stdio.h>
#include <sys/ioctl.h>

#ifndef	INADDR_NONE
#define	INADDR_NONE	0xffffffff
#endif	/* INADDR_NONE */

namespace networklib {

class SocketClient {
public:
	SocketClient(char *host, char *service);
	virtual ~SocketClient();
	int connectToServer();
	void disconnect();
	int sendData(char *buffer, int maxbytes);
	int receiveData(char *buffer, int maxbytes);

	// public variables
	int sock;
	char* errormsg;
	int errorcode;
	bool connected;

private:
	char* _host;
	char* _service;
	char* _transport;
	int	connectsock(char *host, char *service, char *transport);
	int connectTCP(char *host, char *service );

	// error codes
	static const int INVALID_SERVICE = -2; // 4KB
	static const int INVALID_HOST = -1; // 4KB
	static const int INVALID_PROTOCOL = -3; // 4KB
	static const int ERROR_CREATE = -4; // 4KB
	static const int ERROR_CONNECT = -5; // 4KB
};

}

#endif /* SOCKETCLIENT_H_ */
